package com.isunland.managesystem.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.common.DynamicConfigLab;
import com.isunland.managesystem.entity.ProductSalesOriginal;
import com.isunland.managesystem.entity.ProductSearchContent;
import java.util.List;

/**
 * Created by lenovo on 2016/6/15.
 * 产品开发费用开发费用登记。
 */
public class ProductDevelopCountAdapter
    extends ArrayAdapter<ProductSalesOriginal.ProductSalesContent>

{
  private ProductSearchContent countContent;
  private BaseVolleyActivity mActivity;//= (BaseVolleyActivity) getContext();

  public ProductDevelopCountAdapter(Context context,
      List<ProductSalesOriginal.ProductSalesContent> objects, ProductSearchContent countContent) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.countContent = countContent;
    this.mActivity = (BaseVolleyActivity) context;
  }

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2016-05-09 10:00:34 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  public static class ViewHolder {
    public final LinearLayout mHolderRootView;
    public final LinearLayout mHolderOneVg;
    public final LinearLayout mHolderTwoVg;
    public final LinearLayout mHolderThreeVg;
    public final LinearLayout mHolderFourVg;

    public final TextView mTitleOneTv;
    public final TextView mContentOneTv;
    public final TextView mTitleTwoTv;
    public final TextView mContentTwoTv;
    public final TextView mTitleThreeTv;
    public final TextView mContentThreeTv;
    public final TextView mTitleFourTv;
    public final TextView mContentFourTv;

    public final LinearLayout mHolderFiveVg;
    public final TextView mTitleFiveTv;
    public final TextView mContentFiveTv;
    public final LinearLayout mHolderSixVg;
    public final TextView mTitleSixTv;
    public final TextView mContentSixTv;
    public final LinearLayout mHolderSevenVg;
    public final TextView mTitleSevenTv;
    public final TextView mContentSevenTv;
    public final LinearLayout mHolderEightVg;
    public final TextView mTitleEightTv;
    public final TextView mContentEightTv;
    public final LinearLayout mLldevelopCost;
    public final LinearLayout mHolderNineVg;
    public final TextView mTitleNineTv;
    public final TextView mContentNineTv;

    private ViewHolder(LinearLayout rootView, LinearLayout holderOneVg, LinearLayout holderTwoVg,
        LinearLayout holderThreeVg, LinearLayout holderFourVg, LinearLayout holderFiveVg,
        LinearLayout holderSixVg, LinearLayout holderSevenVg, LinearLayout holderEightVg,
        LinearLayout lldevelopCost, LinearLayout holderNineVg,

        TextView tvTitleOneSimpleList, TextView tvContentOneSimpleList,
        TextView tvTitleTwoSimpleList, TextView tvContentTwoSimpleList,
        TextView tvTitleThreeSimpleList, TextView tvContentThreeSimpleList,
        TextView tvTitleFourSimpleList, TextView tvContentFourSimpleList,

        TextView tvTitleFiveSimpleList, TextView tvContentFiveSimpleList,
        TextView tvTitleSixSimpleList, TextView tvContentSixSimpleList,
        TextView tvTitleSevenSimpleList, TextView tvContentSevenSimpleList,
        TextView tvTitleEightSimpleList, TextView tvContentEightSimpleList,
        TextView tvTitleNineSimpleList, TextView tvContentNineSimpleList) {
      this.mHolderRootView = rootView;
      this.mHolderOneVg = holderOneVg;
      this.mHolderTwoVg = holderTwoVg;
      this.mHolderThreeVg = holderThreeVg;
      this.mHolderFourVg = holderFourVg;
      this.mHolderFiveVg = holderFiveVg;
      this.mHolderSixVg = holderSixVg;
      this.mHolderSevenVg = holderSevenVg;
      this.mHolderEightVg = holderEightVg;
      this.mHolderNineVg = holderNineVg;

      this.mTitleOneTv = tvTitleOneSimpleList;
      this.mContentOneTv = tvContentOneSimpleList;
      this.mTitleTwoTv = tvTitleTwoSimpleList;
      this.mContentTwoTv = tvContentTwoSimpleList;
      this.mTitleThreeTv = tvTitleThreeSimpleList;
      this.mContentThreeTv = tvContentThreeSimpleList;
      this.mTitleFourTv = tvTitleFourSimpleList;
      this.mContentFourTv = tvContentFourSimpleList;

      this.mTitleFiveTv = tvTitleFiveSimpleList;
      this.mContentFiveTv = tvContentFiveSimpleList;

      this.mTitleSixTv = tvTitleSixSimpleList;
      this.mContentSixTv = tvContentSixSimpleList;

      this.mTitleSevenTv = tvTitleSevenSimpleList;
      this.mContentSevenTv = tvContentSevenSimpleList;

      this.mTitleEightTv = tvTitleEightSimpleList;
      this.mContentEightTv = tvContentEightSimpleList;

      this.mTitleNineTv = tvTitleNineSimpleList;
      this.mContentNineTv = tvContentNineSimpleList;

      this.mLldevelopCost = lldevelopCost;
    }

    public static ViewHolder create(LinearLayout rootView) {
      LinearLayout holderOneVg = (LinearLayout) rootView.findViewById(R.id.ll_holderOne_simpleList);
      LinearLayout holderTwoVg = (LinearLayout) rootView.findViewById(R.id.ll_holderTwo_simpleList);
      LinearLayout holderThreeVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderThree_simpleList);
      LinearLayout holderFourVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderFour_simpleList);
      TextView tvTitleOneSimpleList = (TextView) rootView.findViewById(R.id.tv_titleOne_simpleList);
      TextView tvContentOneSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentOne_simpleList);
      TextView tvTitleTwoSimpleList = (TextView) rootView.findViewById(R.id.tv_titleTwo_simpleList);
      TextView tvContentTwoSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentTwo_simpleList);
      TextView tvTitleThreeSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleThree_simpleList);
      TextView tvContentThreeSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentThree_simpleList);
      TextView tvTitleFourSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleFour_simpleList);
      TextView tvContentFourSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFour_simpleList);

      LinearLayout holderFiveVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderFive_simpleList);
      TextView tvContentFiveSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFive_simpleList);
      TextView tvTitleFiveSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleFive_simpleList);

      LinearLayout holderSixVg = (LinearLayout) rootView.findViewById(R.id.ll_holderSix_simpleList);
      TextView tvTitleSixSimpleList = (TextView) rootView.findViewById(R.id.tv_titleSix_simpleList);
      TextView tvContentSixSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentSix_simpleList);

      LinearLayout holderSevenVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderSeven_simpleList);
      TextView tvTitleSevenSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleSeven_simpleList);
      TextView tvContentSevenSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentSeven_simpleList);

      LinearLayout holderEightVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderEight_simpleList);
      TextView tvTitleEightSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleEight_simpleList);
      TextView tvContentEightSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentEight_simpleList);
      LinearLayout lldevelopCost = (LinearLayout) rootView.findViewById(R.id.ll_developCost);

      LinearLayout holderNineVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderNine_simpleList);
      TextView tvTitleNineSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleNine_simpleList);
      TextView tvContentNineSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentNine_simpleList);

      return new ViewHolder(rootView, holderOneVg, holderTwoVg, holderThreeVg, holderFourVg,
          holderFiveVg, holderSixVg, holderSevenVg, holderEightVg, lldevelopCost, holderNineVg,

          tvTitleOneSimpleList, tvContentOneSimpleList, tvTitleTwoSimpleList,
          tvContentTwoSimpleList, tvTitleThreeSimpleList, tvContentThreeSimpleList,
          tvTitleFourSimpleList, tvContentFourSimpleList, tvTitleFiveSimpleList,
          tvContentFiveSimpleList, tvTitleSixSimpleList, tvContentSixSimpleList,
          tvTitleSevenSimpleList, tvContentSevenSimpleList, tvTitleEightSimpleList,
          tvContentEightSimpleList, tvTitleNineSimpleList, tvContentNineSimpleList);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_develop_count_list, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);

      //动态配置列   ---隐藏和显示，title
      DynamicConfigLab.newInstance(mActivity,
          getContext().getString(R.string.module_developExpenseEecord))
          .autoConfigTitle(vh.mHolderRootView);
      DynamicConfigLab.newInstance(mActivity,
          getContext().getString(R.string.module_developExpenseEecord))
          .autoConfigVisiblity(vh.mHolderRootView);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }
    ProductSalesOriginal.ProductSalesContent item = getItem(position);
    if (!TextUtils.isEmpty(countContent.getMonth())) {
      vh.mTitleOneTv.setText(R.string.month_colon);
      vh.mContentOneTv.setText(item.getInMonth());//月份
    } else {
      vh.mHolderOneVg.setVisibility(android.view.View.GONE);
    }
    if (!TextUtils.isEmpty(countContent.getMarket())) {
      vh.mContentTwoTv.setText(item.getMarketend());//市场
    } else {
      vh.mHolderTwoVg.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(countContent.getCustomer())) {
      vh.mTitleThreeTv.setText(R.string.cutomer_colon);
      vh.mContentThreeTv.setText(item.getCustomer());//客户
    } else {
      vh.mHolderThreeVg.setVisibility(View.GONE);
    }

    if (!TextUtils.isEmpty(countContent.getSaleman())) {
      vh.mTitleFourTv.setText(R.string.salesman_colon);
      vh.mContentFourTv.setText(item.getSalesManName());//业务员
    } else {
      vh.mHolderFourVg.setVisibility(View.GONE);
    }

    if (!TextUtils.isEmpty(countContent.getProductType())) {
      vh.mTitleFiveTv.setText(R.string.productType_colon);
      vh.mContentFiveTv.setText(item.getProductKind());//类型
    } else {
      vh.mHolderFiveVg.setVisibility(View.GONE);
    }

    vh.mTitleSixTv.setText(R.string.salesProduct);
    vh.mContentSixTv.setText(item.getProduct());//产品

    //      发票单价，进货金额合计，销售金额合计，开发费用合计
    //            vh.mTitleSevenTv.setText(getContext().getString(R.string.receipt_price_count,item.getReceiptPrice()));//产品单价
    //            vh.mContentSevenTv.setText(getContext().getString(R.string.plan_money_all,item.getPlanMoney()));//进货金额合计
    //            vh.mTitleEightTv.setText(getContext().getString(R.string.real_money_all,item.getRealMoney()));// 销售金额合计
    //            vh.mContentEightTv.setText(getContext().getString(R.string.develop_cost_all,item.getDevelopCost()));//开发费用合计
    if (null == item.getReceiptPrice()) {
      vh.mTitleSevenTv.setText(getContext().getString(R.string.receipt_price_count, ""));//产品单价
    } else {
      vh.mTitleSevenTv.setText(
          getContext().getString(R.string.receipt_price_count, item.getReceiptPrice()));//产品单价
    }
    if (null == item.getPlanMoney()) {
      vh.mContentSevenTv.setText(getContext().getString(R.string.plan_money_all, ""));//进货金额合计
    } else {
      vh.mContentSevenTv.setText(
          getContext().getString(R.string.plan_money_all, item.getPlanMoney()));//进货金额合计
    }
    if (null == item.getRealMoney()) {
      vh.mTitleEightTv.setText(getContext().getString(R.string.real_money_all, ""));// 销售金额合计
    } else {
      vh.mTitleEightTv.setText(
          getContext().getString(R.string.real_money_all, item.getRealMoney()));// 销售金额合计
    }
    //            if(null==item.getDevelopCost()){
    //                vh.mContentEightTv.setText(getContext().getString(R.string.develop_cost_all,""));//开发费用合计
    //            }else {
    //                vh.mContentEightTv.setText(getContext().getString(R.string.develop_cost_all,item.getDevelopCost()));//开发费用合计
    //            }

    if (null == item.getActivityCost()) {
      vh.mContentEightTv.setText(getContext().getString(R.string.activity_cost_all, ""));// 业务活动费和基金
    } else {
      vh.mContentEightTv.setText(
          getContext().getString(R.string.activity_cost_all, item.getActivityCost()));//  业务活动费和基金
    }
    if (null == item.getIncreaseCost()) {
      vh.mTitleNineTv.setText(getContext().getString(R.string.increase_cost_all, ""));//业务增长费合计
    } else {
      vh.mTitleNineTv.setText(
          getContext().getString(R.string.increase_cost_all, item.getIncreaseCost()));//业务增长费合计
    }
    if (null == item.getDevelopCost()) {
      vh.mContentNineTv.setText(getContext().getString(R.string.develop_cost_all, ""));//开发费用合计
    } else {
      vh.mContentNineTv.setText(
          getContext().getString(R.string.develop_cost_all, item.getDevelopCost()));//开发费用合计
    }

    return vh.mHolderRootView;
  }

  private LayoutInflater mInflater;
}


